using Devonline.AspNetCore;
using Devonline.Communication.Server;
using Devonline.Core;
using Serilog;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, logger) => logger.ReadFrom.Configuration(context.Configuration));
var appSetting = builder.AddSetting<HostSetting>();

// Add services to the container.
var services = builder.Services;
services.AddLogging();
services.AddHttpContextAccessor();
services.AddResponseCompression();
services.AddCommunicationServer(appSetting);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else if (appSetting.ProtocolType == ProtocolType.Https || appSetting.ProtocolType == ProtocolType.Wss)
{
    app.UseHsts();
    app.UseHttpsRedirection();
}

app.UseRouting();
app.UseResponseCompression();
app.UseCommunicationServer(appSetting);
app.Run();